'''
Created on May 15, 2012

@author: thomas_dao
'''

'''
To create ticket and add paypal key
'''

from web.base import BaseHandler
from web import urls, util
from web import base
from entity.entity import Ticket, Event
from google.appengine.ext.ndb import model
import json
from google.appengine.ext import deferred
from app import taskqueue


class CreateHandler(BaseHandler):
    @base.user_required
    def post(self):
        ticket = Ticket()
        ticket.price = float(self.request.params.get('price'))
        ticket.detail = self.request.params.get('detail')
        ticket.category = self.request.params.get('category')
        event_key = model.Key(Event, int(self.request.params.get('event_id')))
        ticket.event = event_key
        ticket.put()
        
        # Defer this job
        deferred.defer(taskqueue.get_paypal_key, ticket.key)
        
        self.response.write(json.dumps(util.ndb_to_dict(ticket)))
    

class ReadHandler(BaseHandler):
    def get(self):
        pass
    

class UpdateHandler(BaseHandler):
    def post(self):
        pass
    

class DeleteHandler(BaseHandler):
    def post(self):
        pass    


app = urls.app

def main():
    app.run()

if __name__ == '__main__':
    main()